{%- if header.lsys -%}
logical-systems {{ header.lsys }}
{%- else -%}
firewall {
   family inet {
      replace:
      /*
       * {{ header.comment }}
       */
      filter {{ header.filter }} {
         {%- for term in terms -%}
         {%- if term.comment %}
         /* 
          * {{ term.comment }}
          */
         {%- endif %}
         term {{ term.name }} {
            from {
               {% if term.srcprefix -%}
               source-prefix-list {
                  {% for item in term.srcprefix -%}
                  {{ item }};
                  {% endfor %}
               }
               {%- endif %}
               {% if term.srcaddr -%}
               source-address {
                  {% for item in term.srcaddr -%}
                  {{ item }};
                  {% endfor %}
               }
               {%- endif %}
               {% if term.dstprefix -%}
               destination-prefix-list {
                  {% for item in term.dstprefix -%}
                  {{ item }};
                  {% endfor %}
               }
               {%- endif %}
               {% if term.dstaddr -%}
               destination-address {
                  {% for item in term.dstaddr -%}
                  {{ item }};
                  {% endfor %}
               }
               {%- endif %}
               {%- if term.protocol %}
               {%- if term.protocol|length == 1 %}
               protocol {{ term.protocol|last }};
               {% else %}
               protocol [{% for ix in term.protocol %} {{ix}} {% endfor %}];
               {%- endif %}
               {%- endif %}
               {%- if term.dstport %}
               {%- if term.dstport|length == 1 %}
               destination-port {{ term.dstport|last }};
               {% else %}
               destination-port [{% for ix in term.dstport %} {{ix}} {% endfor %}];
               {%- endif %}
               {%- endif %}
            }
         }
         {% endfor %}
      }
   }
}
{%- endif -%}
